package util;

import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class RandomUtil {
    private static final Random random = new Random(System.currentTimeMillis());

    public static int generateOneNumber(int minNum, int maxNum) {
        if (maxNum <= minNum) {
            return minNum;
        }
        return random.nextInt(maxNum) + minNum;
    }

    public static List<Integer> GenerateNumberList(int numCount, int maxNum, int minNum) {
        if (maxNum - minNum + 1 < numCount) {

            return new java.util.ArrayList<Integer>();
        }
        if (maxNum <= minNum) {

            return new java.util.ArrayList<Integer>();
        }

        // ####1#33#33##
        int[] container = new int[maxNum - minNum];
        // ########
        Integer[] result = new Integer[numCount];
        Random random = new Random(System.currentTimeMillis());
        for (int i = minNum; i < maxNum; i++) {
            container[i] = i;
        }
        int index = 0;
        int value = 0;
        for (int i = 0; i < numCount; i++) {
            // #[1,container.Count + 1)#######，#########container#####
            index = random.nextInt(container.length - 1 - i);
            // ############container###
            value = container[index];
            // ##############
            result[i] = value;
            // ##################
            container[index] = container[container.length - i - 1];
            // ############
            container[container.length - i - 1] = value;
        }

        // result.Sort();##
        return Arrays.asList(result);
    }
}
